// eslint-disable-next-line no-shadow
export enum NODE_ATTRS_TYPE {
  INPUT = 0,
  TEXTAREA = 1,
  BUTTON = 2,
  SELECT = 3,
  SWITCH = 4,
  RADIO = 5,
  CHECKBOX = 6,
  CASCADE_SELECT = 7,
  CUSTOM_EVENT = 99,
}
// eslint-disable-next-line no-shadow
export enum NODE_EVENT_TYPE {
  EXECUTE = 0,
  TASK = 1,
  CUSTOM = 99,
}

export interface NodeItemOption {
  label: string;
  value: string;
}
export interface NodeItem {
  key: string;
  keyAttach?: string;
  customLabel?: string;
  label: string;
  type: NODE_ATTRS_TYPE;
  toArray?: boolean;
  buttonName?: string;
  options?: Array<NodeItemOption>;
  disabled?: boolean;
  defaultOption?: string;
  defaultValue?: any;
  multiple?: boolean;
  eventType?: NODE_EVENT_TYPE;
  eventName?: string;
  cascadeKey?: string;
  cascadeValue?: string;
  enableNodes: Array<string>;
  disableNodes: Array<string>;
  // eslint-disable-next-line @typescript-eslint/ban-types
  valueGenerateFunction?: Function;
}

export const NODE_ATTRS_DEFINE: Array<NodeItem> = [
  {
    label: '名称',
    type: NODE_ATTRS_TYPE.INPUT,
    key: 'name',
    enableNodes: ['*'],
    disableNodes: ['bpmn:startEvent', 'bpmn:endEvent'],
  },
  {
    label: '描述',
    type: NODE_ATTRS_TYPE.TEXTAREA,
    toArray: true,
    key: 'documentation',
    enableNodes: ['*'],
    disableNodes: ['bpmn:startEvent', 'bpmn:endEvent'],
  },
  {
    label: '跳转条件',
    type: NODE_ATTRS_TYPE.INPUT,
    key: 'flowable:conditionExpression',
    enableNodes: ['bpmn:sequenceFlow'],
    disableNodes: [],
  },
  {
    label: '跳过表达式',
    type: NODE_ATTRS_TYPE.INPUT,
    key: 'flowable:skipExpression',
    enableNodes: ['bpmn:sequenceFlow'],
    disableNodes: [],
  },
  {
    label: '节点类型',
    type: NODE_ATTRS_TYPE.RADIO,
    key: 'flowable:flowType',
    keyAttach: 'multiInstanceLoopCharacteristics',
    enableNodes: ['bpmn:userTask'],
    disableNodes: ['bpmn:sequenceFlow'],
    defaultValue: 'SINGLE',
    valueGenerateFunction: (data: any) => {
      console.log(data['flowable:flowType']);
      return data['flowable:flowType'] === 'MULTI'
        ? { 'isSequential': true, 'flowable:collection': `${data.id}_multiTag` }
        : undefined;
    },
    options: [
      {
        value: 'MULTI',
        label: '会审',
      },
      {
        value: 'SINGLE',
        label: '单例',
      },
    ],
  },
  {
    label: '执行监听器',
    type: NODE_ATTRS_TYPE.BUTTON,
    disabled: true,
    key: 'flowable:taskListener',
    defaultValue: [
      {
        event: 'create',
        // eslint-disable-next-line no-template-curly-in-string
        delegateExpression: '${standardCldTaskListener}',
      },
      {
        event: 'assignment',
        // eslint-disable-next-line no-template-curly-in-string
        delegateExpression: '${standardCldTaskListener}',
      },
      {
        event: 'complete',
        // eslint-disable-next-line no-template-curly-in-string
        delegateExpression: '${standardCldTaskListener}',
      },
      {
        event: 'delete',
        // eslint-disable-next-line no-template-curly-in-string
        delegateExpression: '${standardCldTaskListener}',
      },
    ],
    eventType: NODE_EVENT_TYPE.TASK,
    enableNodes: ['bpmn:userTask'],
    disableNodes: [],
  },
  {
    label: '事件',
    type: NODE_ATTRS_TYPE.CUSTOM_EVENT,
    key: 'eventList',
    toArray: true,
    customLabel: 'title',
    buttonName: '选择',
    eventName: 'chooseEvent',
    enableNodes: ['bpmn:userTask'],
    disableNodes: ['bpmn:sequenceFlow'],
  },
  {
    label: '审批人类型',
    type: NODE_ATTRS_TYPE.SELECT,
    key: 'flowable:defaultDealerIdentity',
    enableNodes: ['bpmn:userTask'],
    disableNodes: ['bpmn:sequenceFlow'],
    options: [
      {
        value: 'UC',
        label: '用户',
      },
      {
        value: 'UG',
        label: '用户组',
      },
      {
        value: 'UP',
        label: '岗位',
      },
      {
        value: 'SO',
        label: '组织',
      },
      {
        value: 'UA',
        label: '指定机器人',
      },
    ],
  },
  {
    label: '人员',
    type: NODE_ATTRS_TYPE.CUSTOM_EVENT,
    key: 'personInfo',
    toArray: true,
    keyAttach: 'flowable:candidateUsers',
    customLabel: 'name',
    buttonName: '选择',
    eventName: 'choosePerson',
    enableNodes: ['bpmn:userTask'],
    disableNodes: ['bpmn:sequenceFlow'],
    cascadeKey: 'flowable:defaultDealerIdentity',
    cascadeValue: 'UC',
  },
  {
    label: '人员组',
    type: NODE_ATTRS_TYPE.CUSTOM_EVENT,
    key: 'personInfo',
    toArray: true,
    keyAttach: 'flowable:candidateGroups',
    customLabel: 'name',
    buttonName: '选择',
    eventName: 'choosePersonGroups',
    enableNodes: ['bpmn:userTask'],
    disableNodes: ['bpmn:sequenceFlow'],
    cascadeKey: 'flowable:defaultDealerIdentity',
    cascadeValue: 'UG',
  },
  {
    label: '岗位',
    type: NODE_ATTRS_TYPE.CUSTOM_EVENT,
    key: 'personInfo',
    toArray: true,
    keyAttach: 'flowable:candidateGroups',
    customLabel: 'name',
    buttonName: '选择',
    eventName: 'choosePost',
    enableNodes: ['bpmn:userTask'],
    disableNodes: ['bpmn:sequenceFlow'],
    cascadeKey: 'flowable:defaultDealerIdentity',
    cascadeValue: 'UP',
  },
  {
    label: '组织',
    type: NODE_ATTRS_TYPE.CUSTOM_EVENT,
    key: 'personInfo',
    toArray: true,
    keyAttach: 'flowable:candidateGroups',
    customLabel: 'name',
    buttonName: '选择',
    eventName: 'chooseOrg',
    enableNodes: ['bpmn:userTask'],
    disableNodes: ['bpmn:sequenceFlow'],
    cascadeKey: 'flowable:defaultDealerIdentity',
    cascadeValue: 'SO',
  },
  {
    label: '指定机器人',
    type: NODE_ATTRS_TYPE.CUSTOM_EVENT,
    key: 'personInfo',
    toArray: true,
    keyAttach: 'flowable:candidateUsers',
    customLabel: 'name',
    buttonName: '选择',
    eventName: 'chooseRobot',
    enableNodes: ['bpmn:userTask'],
    disableNodes: ['bpmn:sequenceFlow'],
    cascadeKey: 'flowable:defaultDealerIdentity',
    cascadeValue: 'UA',
  },
  {
    label: '跳过方式',
    type: NODE_ATTRS_TYPE.SELECT,
    key: 'flowable:skipType',
    enableNodes: ['bpmn:userTask'],
    disableNodes: [],
    options: [
      {
        value: 'NOT_SKIP',
        label: '不跳过',
      },
      {
        value: 'NEIGHBORING_SKIP',
        label: '相邻重复跳过',
      },
    ],
  },
  {
    label: '通知方式',
    type: NODE_ATTRS_TYPE.RADIO,
    key: 'flowable:notificationMethod',
    enableNodes: ['bpmn:userTask'],
    disableNodes: [],
    defaultValue: '待办',
    options: [
      {
        value: '待办',
        label: '待办',
      },
      {
        value: '待阅',
        label: '待阅',
      },
    ],
  },
];
